package com.macro.mall.uitls;


import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradeWapPayRequest;

/**
 * @Author：Minxiao Hao
 * @Description:
 * @name：PayTest
 * @Date：2024/10/28 22:31
 */
public class PayTest {


    public class AlipayConfig {
        // 商户appid
        public static String APPID = "9021000141660856";
        // 私钥 pkcs8格式的
        public static String RSA_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCm/kMGImqeaCQ+8QJ+WtTngTPSbZ8TX1B2KWVxJG3g+AxqORMDdNA6gfp90Q9NePmISv67hdZ+tr9B2ttrGL27xOzMLii/QWFNtPAo5LwQuilK12QUQIHYPFCrrrFJvukKhrO4aFXTC/RnBVGLqucHrE7cSSQYL32FwSH7ivATaz/P3R8yRP2KwY+F3PV+oME6AfLojA2Tn1hwu6EHc2DIv1W9wwZ9rrot2lt59ueYJMVOBq/5vncPR2rlFZBVVVhJihvqA7gOZcGB82OTOLV5yQ5Jn9nKMr14CfQ8Z/BPcaXz2d2yUiU7v3AEqk4Txh8Q2bf9Lh7HBF8QTTFU93BFAgMBAAECggEBAJH4ug+3r+kt8VkPhXV74pVG7EypxB7D92qCfwjqph271eZYY5Vm28n46kRmpXC8KauImqjCsh9rkT14mMpCA0AKQE+unbGo7exmGHQ2lWotwICKTRIi3R1ug7m+53wmJEEuRBUTJspnrckL7h8fUfn0Fa8bRDDb+mYbz5+48GiXrVzsBiyNJGz3R45nUmJYon0PTSDhSn2RLsi0q9SrjhvMDPIy7x4PZFi/7IrE6GqPCyUJ+TRzrWNk4AaTbk7hu5fDbtewCxnfZW8FZqdz3r44jjIPjw4ijEV4UClhD0vfrVePTu/yFuO7HB/vlHr1JFf9Ewk+2aN14SElgL/GyAECgYEA9jhG7gsZPE/xQzhVf1k+IzwM1Gs8oox+vZh8zGoCy+SVjF75BrOr6XZRkgBMhGFF7pIvwRNgiUcwXOzIOI67mngkvjbLStVG5oFwYs0sOoWIwGKptla3J46Xnw3ED3vrp9MOwZ1HzRYYyV2jhG7/zIkIGAdpZ4JwEg7t0Ecn2kUCgYEAraBbaPFH90q7iv78wfNXAPCg0xw1FjCO8xf4z+Yio5ilPss9u7wg/IA6Z3tdvBGEzwU2CkBE8L+e4lb4VtlvoWq+pN5V0F8EgIRwMO3mBYP6QCvn9pGN+iCkSAcSsxyJvtYhp0Ap28h+8m2vZBJQV5fQpWWkvh8cddYExGbFngECgYEAgJ2hH5OYmRLBWnXA44cAmHMz2Hoz8E0nn25aMoVl9I/xNqQdvUx5jriJn5ScY8JUP20JmPfAQ7V2I/RkGncktGnx95Kz2uFR6fLPfCzk36UFbEmdkWv2vKkVtrYAJn56+O2dFbJM4WqbhARv+CvrXzJtke+9NZ7DYAuAWn3w6WkCgYAgAN7YiSDqxCutgzKzzVbMJY5/W0Otw2WWCWUjbRgVb52F5ZCLejHaWQhq6qJseA4y2pMLcK1Ecw2mSsGbwJiC+FoLqa/HqLv7tG25lyA/BASsr2siV9IDuOCPJj6cJTZ+ppmtanZMvLgpl24s0/NbMfCTjBjBsppcXgai7Q6gAQKBgCbLajKsvGOUtwJplc8zRdxYD+Mjri3m1uBkF8i/ekdeVKj2/rYFm6kiFfj008oOJRZSWPHslHw515RP4MISE3TPeE/gN6PkSYmMktgDcJQddvuWLncSdw2RJa5tOOm08BykU9Obt9iDjYR6n/KZ3KWCBP4Xio6ju79BH/4kgW+5";
        // 服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
        public static String notify_url = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/notify_url.jsp";
        // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
        public static String return_url = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/return_url.jsp";
        // 请求网关地址
        public static String URL = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
        // 编码
        public static String CHARSET = "UTF-8";
        // 返回格式
        public static String FORMAT = "json";
        // 支付宝公钥
        public static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtXgzKBYjrpLueJcqDOv+cNIJuh2w1fbYx7dvpCQcb7ebl4ShtpF7iY3GFsX9Ct3ht3fziqaldnITOAigzz7dCrQQ8s7GHty3LORu5FWksufk7clluFdtVzNK8iQTOeyftNiaNZNS2ybmQUgEmcxGByCaw2qV2CN3ubJZLYth50bNGzLb7188QwLRMCII/zaHEUvawlDJCwNK09847pefbQ73Gd3rmMiAZdxR2CXfOyqHp/5eSuMQOr2aoHQbZFiPyxVlv4LSAcdpJ0CsUQuWmZ8NcSNThVZsEuAFVkhs6pqxDNBGILiAiWuysbgKi/VbsC5Ss+A5kw/3J8BhneMyEQIDAQAB";
        // 日志记录目录
        public static String log_path = "/log";
        // RSA2
        public static String SIGNTYPE = "RSA2";
    }

    public static void main(String[] args){
        // 商户订单号，商户网站订单系统中唯一订单号，必填
        String out_trade_no = "852852";
        // 订单名称，必填
        String subject = "asdfasdfsdaf";
        System.out.println(subject);
        // 付款金额，必填
        String total_amount="8888";
        // 商品描述，可空
        String body = "";
        // 超时时间 可空
        String timeout_express="";
        // 销售产品码 必填
        String product_code="QUICK_WAP_WAY";
        /**********************/
        // SDK 公共请求类，包含公共请求参数，以及封装了签名与验签，开发者无需关注签名与验签
        //调用RSA签名方式
        AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE);
        AlipayTradeWapPayRequest alipay_request=new AlipayTradeWapPayRequest();

        // 封装请求支付信息
        AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
        model.setOutTradeNo(out_trade_no);
        model.setSubject(subject);
        model.setTotalAmount(total_amount);
        model.setBody(body);
        model.setTimeoutExpress(timeout_express);
        model.setProductCode(product_code);
        alipay_request.setBizModel(model);
        // 设置异步通知地址
        alipay_request.setNotifyUrl(AlipayConfig.notify_url);
        // 设置同步地址
        alipay_request.setReturnUrl(AlipayConfig.return_url);

        // form表单生产
        String form = "";
        // 调用SDK生成表单
        try {
            form = client.pageExecute(alipay_request).getBody();
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
        System.out.println(form);

    }
}
